<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
	<xsl:import href="urn:docbkx:stylesheet" />
	
	<xsl:import href="highlight-fo.xsl"/>

    <!--###################################################-->
    <!--##                Extensions                     ##-->
    <!--###################################################-->
	<xsl:param name="use.extensions">1</xsl:param>
	<xsl:param name="tablecolumns.extension">0</xsl:param>
	<xsl:param name="fop1.extensions">1</xsl:param>

    <!--###################################################-->
    <!--##             Table of Contents                 ##-->
    <!--###################################################-->
	<xsl:param name="generate.toc">
		book toc
	</xsl:param>
	<xsl:param name="toc.section.depth">3</xsl:param>
	<xsl:param name="autotoc.label.separator" select="'.  '" />


    <!--###################################################-->
    <!--##                  Labels                       ##-->
    <!--###################################################-->
    <!-- Label Chapters and Sections (numbering) -->
	<xsl:param name="chapter.autolabel">1</xsl:param>
	<xsl:param name="section.autolabel">1</xsl:param>
	<xsl:param name="section.label.includes.component.label">1</xsl:param>


    <!--###################################################-->
    <!--##                  Titles                       ##-->
    <!--###################################################-->
	<xsl:param name="title.margin.left">0pc</xsl:param>
	<xsl:param name="formal.title.placement">
		figure after 
		example before 
		equation before 
		table before 
		procedure before
	</xsl:param>


    <!--###################################################-->
    <!--##                Programlistings                ##-->
    <!--###################################################-->
    <!-- Verbatim text formatting (programlistings) -->
	<xsl:attribute-set name="verbatim.properties">
		<xsl:attribute name="space-before.minimum">1em</xsl:attribute>
		<xsl:attribute name="space-before.optimum">1em</xsl:attribute>
		<xsl:attribute name="space-before.maximum">1em</xsl:attribute>
		<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
		<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
		<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
		<xsl:attribute name="border-color">#444444</xsl:attribute>
		<xsl:attribute name="border-style">solid</xsl:attribute>
		<xsl:attribute name="border-width">0.1pt</xsl:attribute>
		<xsl:attribute name="padding-top">0.5em</xsl:attribute>
		<xsl:attribute name="padding-left">0.5em</xsl:attribute>
		<xsl:attribute name="padding-right">0.5em</xsl:attribute>
		<xsl:attribute name="padding-bottom">0.5em</xsl:attribute>
		<xsl:attribute name="margin-left">0.5em</xsl:attribute>
		<xsl:attribute name="margin-right">0.5em</xsl:attribute>
	</xsl:attribute-set>

	<xsl:param name="highlight.source" select="1"/>
	
	<xsl:attribute-set name="monospace.verbatim.properties">
        <xsl:attribute name="font-size">
            <xsl:value-of select="$body.font.small * 1.0"/>
            <xsl:text>pt</xsl:text>
        </xsl:attribute>
    </xsl:attribute-set>
    
    <!-- Shade (background) programlistings -->
	<xsl:param name="shade.verbatim">1</xsl:param>
	<xsl:attribute-set name="shade.verbatim.style">
		<xsl:attribute name="wrap-option">wrap</xsl:attribute>
		<xsl:attribute name="background-color">#f0f0f0</xsl:attribute>
	</xsl:attribute-set>


    <!--###################################################-->
    <!--##                  Callouts                     ##-->
    <!--###################################################-->
    <xsl:param name="callout.extensions">1</xsl:param>
    <xsl:param name="callout.defaultcolumn">90</xsl:param>
    <xsl:param name="callout.graphics">0</xsl:param>
    <xsl:param name="callout.unicode.number.limit" select="'0'"/>
    <xsl:template name="callout-bug">
        <xsl:param name="conum" select='1'/>
        <fo:inline
            color="black"
            padding-top="0.1em"
            padding-bottom="0.1em"
            padding-start="0.2em"
            padding-end="0.2em"
            baseline-shift="0.1em"
            font-weight="bold"
            font-size="75%">
            <xsl:text>(</xsl:text>
            <xsl:value-of select="$conum"/>
            <xsl:text>)</xsl:text>
        </fo:inline>
    </xsl:template>

    <!--###################################################-->
    <!--##               The cover page                  ##-->
    <!--###################################################-->
	<xsl:template name="book.titlepage.recto">
		<fo:block>
			<fo:table table-layout="fixed" width="175mm">
				<fo:table-column column-width="175mm" />
				<fo:table-body>
					<fo:table-row>
						<fo:table-cell text-align="center">
							<fo:block>
								<fo:external-graphic src="file:src/docbkx/images/logo.png" />
							</fo:block>
							<fo:block font-family="Helvetica" font-size="22pt"
								padding-before="10mm">
								<xsl:value-of select="bookinfo/subtitle" />
							</fo:block>
							<fo:block font-family="Helvetica" font-size="12pt"
								padding="10mm">
								<xsl:text>Version </xsl:text>
								<xsl:value-of select="bookinfo/releaseinfo" />
							</fo:block>
						</fo:table-cell>
					</fo:table-row>
					<fo:table-row>
						<fo:table-cell text-align="center">
							<fo:block font-family="Helvetica" font-size="14pt"
								padding="10mm">
								<xsl:value-of select="bookinfo/pubdate" />
							</fo:block>
						</fo:table-cell>
					</fo:table-row>
					<fo:table-row>
						<fo:table-cell text-align="center">
							<fo:block font-family="Helvetica" font-size="12pt"
								padding="10mm">
								<xsl:for-each select="bookinfo/authorgroup/author">
									<xsl:if test="position() > 1">
										<xsl:text>, </xsl:text>
									</xsl:if>
									<xsl:value-of select="firstname" />
									<xsl:text> </xsl:text>
									<xsl:value-of select="surname" />
								</xsl:for-each>
							</fo:block>
						</fo:table-cell>
					</fo:table-row>
				</fo:table-body>
			</fo:table>
		</fo:block>
	</xsl:template>
	<xsl:variable name="border.text.limit">37</xsl:variable>
	<xsl:param name="double.sided">1</xsl:param>
	<xsl:param name="header.rule">1</xsl:param>
	<xsl:param name="headers.on.blank.pages">1</xsl:param>
	<xsl:param name="footers.on.blank.pages">1</xsl:param>
	<xsl:param name="header.column.widths" select="'1 0 1'" />
	<xsl:param name="footer.column.widths" select="'1 0 1'" />
	<xsl:template name="component.title.nomarkup">
		<xsl:param name="node" select="." />
		<xsl:variable name="id">
			<xsl:call-template name="object.id">
				<xsl:with-param name="object" select="$node" />
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="title">
			<xsl:apply-templates select="$node" mode="object.title.markup">
				<xsl:with-param name="allow-anchors" select="1" />
			</xsl:apply-templates>
		</xsl:variable>
		<xsl:copy-of select="$title" />
	</xsl:template>


    <!--###################################################-->
    <!--##                   Header                      ##-->
    <!--###################################################-->
	<xsl:template name="header.content">
		<xsl:param name="pageclass" select="''" />
		<xsl:param name="sequence" select="''" />
		<xsl:param name="position" select="''" />
		<xsl:param name="gentext-key" select="''" />
		<fo:block>
			<xsl:choose>
				<xsl:when test="($sequence = 'first' or $pageclass != 'body')">
                    <!-- skip rendering header -->
				</xsl:when>
				<xsl:when test="($sequence='even' and $position='left')">
					<xsl:variable name="text">
						<xsl:call-template name="component.title.nomarkup" />
					</xsl:variable>
					<fo:inline keep-together.within-line="always"
						font-weight="bold">
						<xsl:choose>
							<xsl:when test="string-length($text) &gt; ($border.text.limit + 3)">
								<xsl:value-of
									select="concat(substring($text, 0, $border.text.limit), '...')" />
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$text" />
							</xsl:otherwise>
						</xsl:choose>
					</fo:inline>
				</xsl:when>
				<xsl:when test="($sequence='odd' and $position='right')">
					<fo:inline keep-together.within-line="always">
                        <!-- todo : can this ever be larger than $border.text.limit??? -->
						<fo:retrieve-marker retrieve-class-name="section.head.marker"
							retrieve-position="first-including-carryover" retrieve-boundary="page-sequence" />
					</fo:inline>
				</xsl:when>
				<xsl:when test="$position='left'">
					<xsl:call-template name="draft.text" />
				</xsl:when>
				<xsl:when test="$position='center'">
				</xsl:when>
				<xsl:when test="$position='right'">
					<xsl:call-template name="draft.text" />
				</xsl:when>
				<xsl:when test="$sequence = 'first'">
				</xsl:when>
				<xsl:when test="$sequence = 'blank'">
				</xsl:when>
			</xsl:choose>
		</fo:block>
	</xsl:template>
	<xsl:template name="head.sep.rule">
		<xsl:param name="pageclass" />
		<xsl:param name="sequence" />
		<xsl:param name="gentext-key" />
		<xsl:if test="$header.rule != 0">
			<xsl:attribute name="border-bottom-width">0.5pt</xsl:attribute>
			<xsl:attribute name="border-bottom-style">solid</xsl:attribute>
			<xsl:attribute name="border-bottom-color">#000050</xsl:attribute>
		</xsl:if>
	</xsl:template>


    <!--###################################################-->
    <!--##                   Footer                      ##-->
    <!--###################################################-->
	<xsl:template name="footer.content">
		<xsl:param name="pageclass" select="''" />
		<xsl:param name="sequence" select="''" />
		<xsl:param name="position" select="''" />
		<xsl:param name="gentext-key" select="''" />

		<xsl:variable name="version">
			<xsl:choose>
				<xsl:when test="//releaseinfo">
					<xsl:text>LIQUidFORM </xsl:text>
					<xsl:value-of select="//releaseinfo" />
				</xsl:when>
				<xsl:otherwise>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<fo:block>
			<xsl:choose>
				<xsl:when test="$pageclass = 'titlepage'">
				</xsl:when>
				<xsl:when test="$double.sided = 0">
					<xsl:choose>
						<xsl:when test="$position = 'left'">
							<xsl:value-of select="$version" />
						</xsl:when>
						<xsl:when test="$position = 'right'">
							<fo:page-number />
						</xsl:when>
						<xsl:otherwise>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:when test="$double.sided != 0">
					<xsl:choose>
						<xsl:when
							test="($sequence = 'odd' or $sequence = 'first') and $position='right'">
							<fo:page-number />
						</xsl:when>
						<xsl:when
							test="($sequence = 'odd' or $sequence = 'first') and $position='left'">
							<xsl:value-of select="$version" />
						</xsl:when>
						<xsl:when test="$sequence = 'even' and $position='left'">
							<fo:page-number />
						</xsl:when>
						<xsl:when test="$sequence = 'even' and $position='right'">
							<xsl:value-of select="$version" />
						</xsl:when>
						<xsl:when test="$sequence='blank' and $position='left'">
							<fo:page-number />
						</xsl:when>
						<xsl:when test="$sequence='blank' and $position='right'">
							<xsl:value-of select="$version" />
						</xsl:when>
						<xsl:otherwise>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
				</xsl:otherwise>
			</xsl:choose>
		</fo:block>
	</xsl:template>
	<xsl:template name="foot.sep.rule">
		<xsl:param name="pageclass" />
		<xsl:param name="sequence" />
		<xsl:param name="gentext-key" />
		<xsl:if test="$footer.rule != 0">
			<xsl:attribute name="border-top-width">0.5pt</xsl:attribute>
			<xsl:attribute name="border-top-style">solid</xsl:attribute>
			<xsl:attribute name="border-top-color">#000050</xsl:attribute>
		</xsl:if>
	</xsl:template>

    <!--###################################################-->
    <!--##                Hypenation                     ##-->
    <!--###################################################-->
	<xsl:param name="hyphenate">false</xsl:param>
	<xsl:param name="hyphenation-character">-</xsl:param>


    <!--###################################################-->
    <!--##             Paper & Page Size                 ##-->
    <!--###################################################-->
	<xsl:param name="alignment">justify</xsl:param>
	<xsl:param name="line-height">1.4</xsl:param>
	<xsl:param name="paper.type" select="'A4'" />
	<xsl:param name="page.margin.top">15mm</xsl:param>
	<xsl:param name="region.before.extent">10mm</xsl:param>
	<xsl:param name="body.margin.top">15mm</xsl:param>
	<xsl:param name="body.margin.bottom">15mm</xsl:param>
	<xsl:param name="region.after.extent">10mm</xsl:param>
	<xsl:param name="page.margin.bottom">15mm</xsl:param>
	<xsl:param name="page.margin.outer">30mm</xsl:param>
	<xsl:param name="page.margin.inner">30mm</xsl:param>


    <!--###################################################-->
    <!--##              Custom Toc Line                  ##-->
    <!--###################################################-->
	<xsl:template name="toc.line">
		<xsl:variable name="id">
			<xsl:call-template name="object.id" />
		</xsl:variable>
		<xsl:variable name="label">
			<xsl:apply-templates select="." mode="label.markup" />
		</xsl:variable>
		<fo:block text-align-last="justify" end-indent="{$toc.indent.width}pt"
			last-line-end-indent="-{$toc.indent.width}pt">
			<fo:inline keep-with-next.within-line="always">
				<fo:basic-link internal-destination="{$id}">
                    <!-- Chapter titles should be bold. -->
					<xsl:choose>
						<xsl:when test="local-name(.) = 'chapter'">
							<xsl:attribute name="font-weight">bold</xsl:attribute>
						</xsl:when>
					</xsl:choose>
					<xsl:if test="$label != ''">
						<xsl:copy-of select="$label" />
						<xsl:value-of select="$autotoc.label.separator" />
					</xsl:if>
					<xsl:apply-templates select="."
						mode="titleabbrev.markup" />
				</fo:basic-link>
			</fo:inline>
			<fo:inline keep-together.within-line="always">
				<xsl:text> </xsl:text>
				<fo:leader leader-pattern="dots" leader-pattern-width="3pt"
					leader-alignment="reference-area" keep-with-next.within-line="always" />
				<xsl:text> </xsl:text>
				<fo:basic-link internal-destination="{$id}">
					<fo:page-number-citation ref-id="{$id}" />
				</fo:basic-link>
			</fo:inline>
		</fo:block>
	</xsl:template>


    <!--###################################################-->
    <!--##                  Titles                       ##-->
    <!--###################################################-->
	<xsl:param name="title.color">#000050</xsl:param>
	<xsl:attribute-set name="book.titlepage.recto.style">
		<xsl:attribute name="font-family">
            <xsl:value-of select="$title.fontset" />
        </xsl:attribute>
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="font-weight">bold</xsl:attribute>
		<xsl:attribute name="font-size">12pt</xsl:attribute>
		<xsl:attribute name="text-align">center</xsl:attribute>
	</xsl:attribute-set>
	<xsl:attribute-set name="chapter.titlepage.recto.style">
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="background-color">white</xsl:attribute>
		<xsl:attribute name="font-size">24pt</xsl:attribute>
		<xsl:attribute name="font-weight">bold</xsl:attribute>
		<xsl:attribute name="text-align">left</xsl:attribute>
		<xsl:attribute name="padding-left">1em</xsl:attribute>
		<xsl:attribute name="padding-right">1em</xsl:attribute>
	</xsl:attribute-set>
	<xsl:attribute-set name="preface.titlepage.recto.style">
		<xsl:attribute name="font-family">
            <xsl:value-of select="$title.fontset" />
        </xsl:attribute>
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="font-size">12pt</xsl:attribute>
		<xsl:attribute name="font-weight">bold</xsl:attribute>
	</xsl:attribute-set>
	<xsl:template match="title" mode="chapter.titlepage.recto.auto.mode">
		<fo:block xsl:use-attribute-sets="chapter.titlepage.recto.style">
			<xsl:call-template name="component.title">
				<xsl:with-param name="node" select="ancestor-or-self::chapter[1]" />
			</xsl:call-template>
		</fo:block>
	</xsl:template>
	<xsl:attribute-set name="section.title.properties">
		<xsl:attribute name="font-family">
            <xsl:value-of select="$title.font.family" />
        </xsl:attribute>
		<xsl:attribute name="font-weight">bold</xsl:attribute>
		<xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
		<xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
		<xsl:attribute name="space-before.optimum">1.0em</xsl:attribute>
		<xsl:attribute name="space-before.maximum">1.2em</xsl:attribute>
		<xsl:attribute name="text-align">left</xsl:attribute>
		<xsl:attribute name="start-indent">
            <xsl:value-of select="$title.margin.left" />
        </xsl:attribute>
	</xsl:attribute-set>
	<xsl:attribute-set name="section.title.level1.properties">
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="font-size">
            <xsl:value-of select="$body.font.master * 1.6" />
            <xsl:text>pt</xsl:text>
        </xsl:attribute>
	</xsl:attribute-set>
	<xsl:attribute-set name="section.title.level2.properties">
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="font-size">
            <xsl:value-of select="$body.font.master * 1.4" />
            <xsl:text>pt</xsl:text>
        </xsl:attribute>
	</xsl:attribute-set>
	<xsl:attribute-set name="section.title.level3.properties">
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="font-size">
            <xsl:value-of select="$body.font.master * 1.3" />
            <xsl:text>pt</xsl:text>
        </xsl:attribute>
	</xsl:attribute-set>
	<xsl:attribute-set name="section.title.level4.properties">
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="font-size">
            <xsl:value-of select="$body.font.master * 1.2" />
            <xsl:text>pt</xsl:text>
        </xsl:attribute>
	</xsl:attribute-set>
	<xsl:attribute-set name="section.title.level5.properties">
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="font-size">
            <xsl:value-of select="$body.font.master * 1.1" />
            <xsl:text>pt</xsl:text>
        </xsl:attribute>
	</xsl:attribute-set>
	<xsl:attribute-set name="section.title.level6.properties">
		<xsl:attribute name="color">
            <xsl:value-of select="$title.color" />
        </xsl:attribute>
		<xsl:attribute name="font-size">
            <xsl:value-of select="$body.font.master" />
            <xsl:text>pt</xsl:text>
        </xsl:attribute>
	</xsl:attribute-set>


    <!--###################################################-->
    <!--##                    Misc                       ##-->
    <!--###################################################-->

    <!-- Format Variable Lists as Blocks (prevents horizontal overflow). -->
	<xsl:param name="variablelist.as.blocks">1</xsl:param>

	<!--
	<xsl:template name="book.titlepage.before.verso">
    </xsl:template>
    <xsl:template name="book.titlepage.verso">
    </xsl:template>
    <xsl:template name="book.titlepage.separator">
    </xsl:template>
	-->
	<xsl:param name="admon.graphics" select="1" />
	<xsl:param name="admon.graphics.extension" select="'.svg'" />
	<xsl:param name="admon.graphics.path" select="'src/docbkx/images/'" />
	<xsl:param name="draft.mode" select="'no'" />
	
	<xsl:param name="insert.xref.page.number" select="'maybe'" />
	
	<xsl:template name="force.page.count">
		<xsl:param name="element" select="local-name(.)"/>
	  	<xsl:param name="master-reference" select="''"/>
	
	  	<xsl:choose>
	    	<!-- double-sided output -->
	    	<xsl:when test="$double.sided != 0">no-force</xsl:when>
	    	<!-- single-sided output -->
	    	<xsl:otherwise>no-force</xsl:otherwise>
	  	</xsl:choose>
	</xsl:template>
	    
    <!--###################################################-->
    <!--##               Fonts & Styles                  ##-->
    <!--###################################################-->
	<xsl:param name="body.font.master">11</xsl:param>
	<xsl:param name="body.font.small">8</xsl:param>
	
	<xsl:template match="*[@role='symbol']">
    	<fo:inline font-family="Symbol">
      		<xsl:apply-templates/>
    	</fo:inline>
  	</xsl:template>
	
	<xsl:attribute-set name="monospace.properties">
		<xsl:attribute name="font-family">
            <xsl:value-of select="$monospace.font.family" />
        </xsl:attribute>
		<xsl:attribute name="font-size">0.8em</xsl:attribute>
	</xsl:attribute-set>
	<xsl:template name="pickfont-sans">
		<xsl:choose>
			<xsl:when test="$fop1.extensions != 0">
				<xsl:text>LiberationSans,sans-serif</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>sans-serif</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="pickfont-serif">
		<xsl:choose>
			<xsl:when test="$fop1.extensions != 0">
				<xsl:text>LiberationSerif,serif</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>serif</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="pickfont-mono">
		<xsl:choose>
			<xsl:when test="$fop1.extensions != 0">
				<xsl:text>LiberationMono,monospace</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>monospace</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:param name="title.font.family">
		<xsl:call-template name="pickfont-sans" />
	</xsl:param>
	<xsl:param name="body.font.family">
		<xsl:call-template name="pickfont-sans" />
	</xsl:param>
	<xsl:param name="monospace.font.family">
		<xsl:call-template name="pickfont-mono" />
	</xsl:param>
	<xsl:param name="sans.font.family">
		<xsl:call-template name="pickfont-sans" />
	</xsl:param>
</xsl:stylesheet>